home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
050a.dms
/
050a.adf
/
EXAMPLE_PROGRAMS
/
example24.AMOS
/
example24.amosSourceCode
Wrap
AMOS Source Code
|
1992-02-26
|
7KB
|
268 lines
'
' THE AMOSZINE CLASSIC PROCEDURES LIBRARY
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'
' PROC NO. : 2
'
' PROC NAME: NEW RGB REQUESTOR
'
' ORIGIN : AMINET CD
'
' AUTHOR : Rob Farnsworth
'
' PURPOSE : Dpaint 3 style palette requestor
'
' PARAMS : See authors comment
'
' COMMENT: This routine is old, but what a cracker!
' I like the fact that you can drag the req
' around the screen and it gives the hex$ for
' the colour you are editing. Useful in development
' as well as in a program, esp a util.
'
'======================================================
' Robert Farnsworth
' 1 Vidovic Ave, Mildura, 3500
'
' Comment from author:
'--------------------
' This palette changer routine originaly came from the Sprite Editor.
' I have modified it so that it can be placed anywhere on the screen by
' supplying the XY coords of the top left corner. It will auto-centre
' on either axis if set to zero - set both to zero and the requester
' is placed in the middle of the screen.
' Another addition is a drag bar, at the top, that allows the requester
' to be moved.
' Works in Lowres and Hires.
'
' Unfold CHANGERGB for parameter info.
'-----------------------------------------------------------------------
'
'A WORKING EXAMPLE
'
Screen Open 0,640,256,16,Hires
Curs Off : Flash Off : Cls 0
Reserve Zone 40
'
For I=0 To Screen Colour-1
Paper I
Print At(0,I);Space$(80)
Next
'
CHANGERGB[0,0,0,2,4]
'
'--------------- Colour changer routines --------------
'
Procedure CHANGERGB[X,Y,SCRN,C1,C2]
'
' Palette changer.
'
' X,Y - Coords of top left corner. (Will auto centre
' if coord is zero)
' SCRN - The screen to put requester on.
' C1,C2 - C1 - Body colour, C2 - The other colour.
'
Shared X1,Y1,X2,Y2,YO,OK,CANCEL,DRAG
Dim RGB(31)
'
SC=Screen
Screen SCRN
Set Font 0 : Rem Select default font
Reset Zone
Reserve Zone Screen Colour+6
' ---
W=204 : H=103 : NCOLS=Screen Colour
' --- Centre requester if X or Y are zero
If X=0 Then X=Screen Width/2-W/2
If Y=0 Then Y=Screen Height/2-H/2
RGBINIT[X,Y,W,H,NCOLS]
Get Block 1,X1,Y1-YO,W+4,H+4+YO
' --- Draw the requester ---
Ink 0,0
Bar X1+3,Y1+3-YO To X1+W+3,Y1+H+3
Ink C1,C2
Bar X1,Y1-YO To X2,Y2
Ink C2,C1
Box X1+1,Y1+1-YO To X2-1,Y2-1
Ink C2,C1
' --- slider bars
For A=0 To 2
Bar X1+7+A*20,Y1+3 To X1+23+A*20,Y2-3
Next
' --- Tic marks
For A=0 To 16
Draw X1+4,Y1+3+A*6 To X1+66,Y1+3+A*6
Next
' --- palette
For A=0 To Min(32,NCOLS)-1
Ink A,A : XX=A mod 8 : YY=A/8
Bar X1+XX*16+72,Y1+YY*16+4 To X1+XX*16+87,Y1+YY*16+20
RGB(A)=Colour(A)
Next
Ink C2,C1
Box X1+71,Y1+3 To X1+88+16*XX,Y1+21+16*YY
' --- OK CANCEL buttons
Box X1+72,Y1+87 To X1+132,Y1+97
Text X1+78,Y1+95,"Cancel"
Box X1+144,Y1+87 To X1+194,Y1+97
Text X1+157,Y1+95,"O.K"
'--- Selected colour
SELCOL=0 : Rem default to colour 0
Ink SELCOL
Bar X1+187,Y1+75 To X1+193,Y1+84
Ink C2
Box X1+186,Y1+74 To X1+194,Y1+85
' --- Drag bar
Ink C2
Bar X1+4,Y1-YO+4 To X2-4,Y1
'------------------------------------------
' --- draw RGB buttons
SFADERS[SELCOL,X1,Y1,C1,C2]
' --- main loop
CHANGING_COLOURS=True
While CHANGING_COLOURS
While Mouse Key=0 : Wend
YM=Y Screen(Y Mouse)-Y1+3 : Z=Mouse Zone
If Z>0 and Z<4
' --- sliders moving
CFADERS[SELCOL,Z-1,YM]
SFADERS[SELCOL,X1,Y1,C1,C2]
End If
If Z>3 and Z<3+NCOLS+1
' --- colour selected
SELCOL=Z-4
Ink SELCOL
Bar X1+187,Y1+75 To X1+193,Y1+84
SFADERS[SELCOL,X1,Y1,C1,C2]
Ink SELCOL
End If
If Z=CANCEL
' --- Cancel
CHANGING_COLOURS=False
End If
If Z=OK
' --- Ok
A=0
Repeat
Colour A,RGB(A) : SPCOL[A,RGB(A)]
Inc A
Until A>=Min(32,NCOLS)
CHANGING_COLOURS=False
End If
If Z=DRAG
' --- Drag bar
WIDTH=W+4 : HEIGHT=H+3+YO
' --- Get req image
Get Block 2,X1,Y1-YO,WIDTH,HEIGHT+1
MX=X Screen(X Mouse) : MY=Y Screen(Y Mouse)
MXO=MX-X1 : MYO=MY-Y1+YO
Gr Writing 2 : Rem XOR
Limit Mouse X Hard(MXO),Y Hard(MYO) To X Hard(Screen Width-(WIDTH-MXO)),Y Hard(Screen Height-(HEIGHT-MYO)-1)
While Mouse Key=1
Box MX-MXO,MY-MYO To MX-MXO+WIDTH,MY-MYO+HEIGHT
OLDX=MX : OLDY=MY
While OLDX=X Screen(X Mouse) and OLDY=Y Screen(Y Mouse) : Wend
MX=X Screen(X Mouse) : MY=Y Screen(Y Mouse)
Box OLDX-MXO,OLDY-MYO To OLDX-MXO+WIDTH,OLDY-MYO+HEIGHT
Wend
Limit Mouse X Hard(0),Y Hard(0) To X Hard(Screen Width),Y Hard(Screen Height)
Gr Writing 1
' --- Restore bg at old location
Put Block 1
' --- Save bg at new location
Get Block 1,MX-MXO,MY-MYO,WIDTH,HEIGHT+1
' --- Put Req at new location
Put Block 2,MX-MXO,MY-MYO
Del Block 2
' --- Re-calc var's & zones ---
X=MX-MXO : Y=MY-MYO+YO
RGBINIT[X,Y,W,H,NCOLS]
End If
Wend
Put Block 1
Screen SC
Del Block 1
End Proc
'
Procedure RGBINIT[X,Y,W,H,NCOLS]
' Calc main vbls & set zones.
' Has to be done twice, hence the proc.
Shared X1,Y1,X2,Y2,YO,OK,CANCEL,DRAG
X1=X : X2=X1+W : Y1=Y : Y2=Y1+H : YO=6
Z=1
For A=0 To 2
Set Zone Z,X1+7+A*20,Y1+3 To X1+23+A*20,Y2-3 : Inc Z
Next
For A=0 To Min(32,NCOLS)-1
Ink A,A : XX=A mod 8 : YY=A/8
Set Zone Z,X1+XX*16+72,Y1+YY*16+4 To X1+XX*16+87,Y1+YY*16+20 : Inc Z
Next
Set Zone Z,X1+72,Y1+87 To X1+132,Y1+97 : OK=Z : Inc Z
Set Zone Z,X1+146,Y1+87 To X1+194,Y1+97 : CANCEL=Z : Inc Z
Set Zone Z,X1+4,Y1-YO+4 To X2-4,Y1 : DRAG=Z
End Proc
'
Procedure CFADERS[S,F,YM]
Dim R(2)
' --- get RGB components of selected colour
C=Colour(S)
R(0)=C/256
R(1)=(C/16) mod 16
R(2)=C mod 16
' --- amplitude of slider (0..15)
V=Max(0,Min(15,15-(YM-7)/6))
' --- set RGB's value
R(F)=V
' --- set selected colour
Colour S,(R(0)*256+R(1)*16+R(2))
' ---
SPCOL[S,Colour(S)]
End Proc
'
Procedure SFADERS[S,X1,Y1,C1,C2]
Shared RGBO
Dim R(2)
'
C=RGBO
R(0)=C/256
R(1)=(C/16) mod 16
R(2)=C mod 16
' --- Erase slider button
Ink C2,C2
For A=0 To 2
V=(15-R(A))*6+4
Bar X1+9+20*A,Y1+V To X1+20+20*A,Y1+V+5
Next
' --- set new colour value
C=Colour(S)
RGBO=C
R(0)=C/256
R(1)=(C/16) mod 16
R(2)=C mod 16
' --- print the colour value in hex
Ink C2,C1
Gr Writing 1
Text X1+72,Y1+82,"Col"+Right$(" "+Str$(S),2)+" Val:$"+Right$("000"+Mid$(Hex$(RGBO),2),3)
Ink C1,C1
' --- draw new slider button
For A=0 To 2
Ink C1,C1
V=(15-R(A))*6+4
Box X1+9+20*A,Y1+V To X1+20+20*A,Y1+V+5
Ink S
Bar X1+10+20*A,Y1+V+1 To X1+19+20*A,Y1+V+4
Next
End Proc
'
Procedure SPCOL[A,B]
If Length(1)>0
Doke Start(1)+2+8*Length(1)+2*A,B
End If
End Proc